<?php 

class log extends CI_Controller{
	
	function __construct() {
        parent::__construct();
		$this->load->model('user_model');
    }
	
	function index(){
	//		$this->load->view('login');
	}
	
	function auth(){
		$username = $this->input->post('username');
		$pass = $this->input->post('password');
		//var_dump($username);
		//var_dump($pass);
		if($username==null || $pass==null){
			redirect('produk');
			
		} else {
			$user = $this->user_model->get_user($username);
			if($user->num_rows() > 0){
				if ($username == $user->row()->username && md5($pass) == $user->row()->password) {
					$username = $user->row()->username;
					$newuser = array(
						'username' => $username,
						'id_user'=> $user->row()->id_user
					);
				
                $this->session->set_userdata($newuser);
				//var_dump($newuser);
			    redirect('produk');
				
            } else{
					 redirect('produk');
					 }
					} else {
						//var_dump($user);
						redirect('produk');
					}
				} 
			}
	
	function logout(){
		$this->session->sess_destroy();
        redirect('produk');
	}
}